package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AttendanceRuleMapper;
import com.ruoyi.system.domain.AttendanceRule;
import com.ruoyi.system.service.IAttendanceRuleService;

/**
 * 考勤规则Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-21
 */
@Service
public class AttendanceRuleServiceImpl implements IAttendanceRuleService
{
    @Autowired
    private AttendanceRuleMapper attendanceRuleMapper;

    /**
     * 查询考勤规则
     *
     * @param id 考勤规则主键
     * @return 考勤规则
     */
    @Override
    public AttendanceRule selectAttendanceRuleById(Long id)
    {
        return attendanceRuleMapper.selectAttendanceRuleById(id);
    }

    /**
     * 查询考勤规则列表
     *
     * @param attendanceRule 考勤规则
     * @return 考勤规则
     */
    @Override
    public List<AttendanceRule> selectAttendanceRuleList(AttendanceRule attendanceRule)
    {
        return attendanceRuleMapper.selectAttendanceRuleList(attendanceRule);
    }

    /**
     * 新增考勤规则
     *
     * @param attendanceRule 考勤规则
     * @return 结果
     */
    @Override
    public int insertAttendanceRule(AttendanceRule attendanceRule)
    {
        attendanceRule.setCreateTime(DateUtils.getNowDate());
        return attendanceRuleMapper.insertAttendanceRule(attendanceRule);
    }

    /**
     * 修改考勤规则
     *
     * @param attendanceRule 考勤规则
     * @return 结果
     */
    @Override
    public int updateAttendanceRule(AttendanceRule attendanceRule)
    {
        attendanceRule.setUpdateTime(DateUtils.getNowDate());
        return attendanceRuleMapper.updateAttendanceRule(attendanceRule);
    }

    /**
     * 批量删除考勤规则
     *
     * @param ids 需要删除的考勤规则主键
     * @return 结果
     */
    @Override
    public int deleteAttendanceRuleByIds(Long[] ids)
    {
        return attendanceRuleMapper.deleteAttendanceRuleByIds(ids);
    }

    /**
     * 删除考勤规则信息
     *
     * @param id 考勤规则主键
     * @return 结果
     */
    @Override
    public int deleteAttendanceRuleById(Long id)
    {
        return attendanceRuleMapper.deleteAttendanceRuleById(id);
    }

    @Override
    public AttendanceRule getRuleByUserId(Long userId) {
        return attendanceRuleMapper.selectRuleByUserId(userId);
    }
}
